#include "hal_keyboard.h"
#include "hk32c030xx_gpio.h"

static void keyboard_init() {
	GPIO_InitTypeDef keyboard_key;
	RCC_AHBPeriphClockCmd(KEY_FLOOR_RCU, ENABLE);
	
	keyboard_key.GPIO_Pin = KEY_FLOOR1_PIN | KEY_FLOOR2_PIN | KEY_FLOOR3_PIN |
						KEY_FLOOR6_PIN | KEY_FLOOR5_PIN | KEY_FLOOR4_PIN;
	keyboard_key.GPIO_Mode = GPIO_Mode_IN;
	keyboard_key.GPIO_OType = GPIO_OType_PP;
	keyboard_key.GPIO_Speed = GPIO_Speed_10MHz;
	keyboard_key.GPIO_PuPd = GPIO_PuPd_NOPULL;
	keyboard_key.GPIO_Schmit = GPIO_Schmit_Disable;
	GPIO_Init(KEY_FLOOR_BASE, &keyboard_key);
}

static uint8_t keyboard_get_floor1() {
	if(GPIO_ReadInputDataBit(KEY_FLOOR_BASE,KEY_FLOOR1_PIN))
		return 0;
	else 
		return 1;
}

static uint8_t keyboard_get_floor2() {
	if(GPIO_ReadInputDataBit(KEY_FLOOR_BASE,KEY_FLOOR2_PIN))
		return 0;
	else 
		return 1;
}

static uint8_t keyboard_get_floor3() {
	if(GPIO_ReadInputDataBit(KEY_FLOOR_BASE,KEY_FLOOR3_PIN))
		return 0;
	else 
		return 1;
}

static uint8_t keyboard_get_floor4() {
	if(GPIO_ReadInputDataBit(KEY_FLOOR_BASE,KEY_FLOOR4_PIN))
		return 0;
	else 
		return 1;
}

static uint8_t keyboard_get_floor5() {
	if(GPIO_ReadInputDataBit(KEY_FLOOR_BASE,KEY_FLOOR5_PIN))
		return 0;
	else 
		return 1;
}

static uint8_t keyboard_get_floor6() {
	if(GPIO_ReadInputDataBit(KEY_FLOOR_BASE,KEY_FLOOR6_PIN))
		return 0;
	else 
		return 1;
}

const key_floor_t g_floor_keyboard_ = {
	keyboard_init,
	keyboard_get_floor1,
	keyboard_get_floor2,
	keyboard_get_floor3,
	keyboard_get_floor4,
	keyboard_get_floor5,
	keyboard_get_floor6,
};

